<template>
  <div>
    <BreakSpace label="采购订单信息" :containerStyle="{ marginBottom: '15px' }" />
    <FormPanel ref="FormPanel" :list="formList" labelWidth="100" :formType="type" :isSubmitBtn="false" @formChange="formChangeHandle2" />

    <BreakSpace label="备件列表" :containerStyle="{ marginBottom: '15px' }" />
<!--    <span>-->
<!--        订购品种合计： <el-input style="width:150px;" label="订购品种合计" size="medium" :disabled="true" v-model="dataSize"></el-input>-->
<!--      </span>-->
    <FilterTable
      ref="tablePeij"
      :isSelectColumn=false
      :columns="partColumns"
      :datakey="'records'"
      columnsRef="notification_maintain_info_02"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
<!--    <div class="scene-table" style="align-content: center">-->
<!--      <div class="table-title" style="text-align: center;margin-top: 10px;">采购品种合计: &nbsp;{{ allSalesNum }}&nbsp; 采购数量合计: &nbsp;{{ allPartNum }} 采购金额合计: &nbsp;{{ allPriceNum }}</div>-->
<!--    </div>-->
    <div class="dialogBottmView">
      <el-button @click="closeDialog('closeDialog')">返 回</el-button>
    </div>
  </div>
</template>

<script>
  import { getDetailData,getDetailTool} from '@/api/partsmanage/sparepartTrace/query';
  import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'carrierTrace',
  mixins: [dictionary],
  props: {
    type: {
      type: String,
      default: 'add'
    },
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    this.saveData = null;
    return {
      formList: this.createFormList(),
      partColumns: this.creatHeaderPartRoleColumns(),
      activeName: 'first',
      saveLoading: false,
      allPartNum:0,
      allSalesNum:0,
      dataSize:0,
      allPriceNum:0
    };
  },
  created() {
    this.init();
  },
  mounted() {
    this.findBuyItems();
  },
  methods: {
    init() {
      this.formList.forEach(x => {
        x.initialValue = this.rowData[x.fieldName];
      });
      getDetailData( {"ID":this.rowData.id}).then(response => {
        var list = response.data.records
        console.log("品种总数");
        console.log()
        this.dataSize=list.length
        if(response.resultCode === 200){
          this.$nextTick(()=>{
            this.$refs.tablePeij.EXECUTE_INSERT(list)
          })
        }
      })
    },
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '服务商代码',
          fieldName: 'DEALER_CODE',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '服务商名称',
          fieldName: 'DEALER_NAME',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '备件订单号',
          fieldName: 'XSDDHM',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '订单类型',
          fieldName: 'XSDDLX',
          disabled: true,
          itemList: this.createDictList('3003'),
        },
        {
          type: 'DATE',
          label: '提报日期',
          fieldName: 'DDTBSJ',
          dateFormat: 'yyyy-MM-dd',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '交货单号',
          fieldName: 'SAPPO',
          disabled: true,
          hidden:true
        },
        {
          type: 'INPUT',
          label: '收货地址',
          fieldName: 'XXSHDZ',
          selfCols: 2,
          maxlength: 1000,
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'XSDDBZ',
          selfCols: 3,
          maxlength: 200,
          disabled: true
        }
      ];
    },
    formChangeHandle(val) {
      this.saveData = val;
    },
    creatHeaderPartRoleColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        // { title: '厂家发货仓库代码', dataIndex: 'BSCKDM', sorter: true },
        // { title: '厂家发货仓库名称', dataIndex: 'bsckmc', sorter: true },
        { title: '备件代码', dataIndex: 'BJXMBH', sorter: true },
        { title: '备件名称', dataIndex: 'BJZWMC', sorter: true },
        { title: '物料组', dataIndex: 'MATERIAL',dictItems:this.createDictList('3054'), sorter: true },
        // { title: '订单号', dataIndex: 'bsddwj', sorter: true, width: 200 },
        { title: '销售包装量', dataIndex: 'BJBJXSZX', sorter: true },
        { title: '采购数量', dataIndex: 'BSTXSL', sorter: true ,summation: true,  summationUnit:"(采购数量合计)",},
        // { title: '入库数量', dataIndex: 'rksl', sorter: true },
        { title: '服务商进价', dataIndex: 'XSXSDJ',precision: 2,sorter: true,numberFormat: true},
        { title: '取消数量', dataIndex: 'QXSL', sorter: true },
        { title: 'B/O数量', dataIndex: 'BSBOSL', sorter: true },
        { title: '出库数量', dataIndex: 'BJFYSL', sorter: true},
        { title: '订单金额', dataIndex: 'XSYSJE', precision: 2, sorter: true, numberFormat: true,summation: true,  summationUnit:"(采购金额合计)",},
      ]
    },
    formChangeHandle2(val) {},

    async findBuyItems() {
      this.allPartNum = 0;
      this.allSalesNum = 0;
      this.allPriceNum = 0;
      let res = await getDetailTool( {"ID":this.rowData.ID});
      this.dataSize = res.data.length
    },
    closeDialog(param) {
      this.$emit('close', { visible: false, type: param });
    }
  }
};
</script>

<style scoped></style>
